package com.zhilianbao.leyaogo.ui.adapter.me;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.bql.pickphotos.PickPhotos;
import com.bql.recyclerview.swipe.SwipeMenuAdapter;
import com.bumptech.glide.Glide;
import com.zhilianbao.leyaogo.R;
import com.zhilianbao.leyaogo.model.response.me.MyOrderResponse;
import com.zhilianbao.leyaogo.utils.ImageUtils;
import com.zhilianbao.leyaogo.utils.Utils;

import java.util.List;

/**
 * Created by liu on 2016/11/25.
 */
public class OrderHorizontalAdapter extends SwipeMenuAdapter<OrderHorizontalAdapter.OrderHorizontalViewHolder> {
    private List<MyOrderResponse.OrderItemBean> mList;
    private Context mContext;

    public OrderHorizontalAdapter(Context context, List<MyOrderResponse.OrderItemBean> list) {
        mList = list;
        this.mContext = context;
    }

    @Override
    public View onCreateContentView(ViewGroup parent, int viewType) {
        return LayoutInflater.from(parent.getContext()).inflate(R.layout.item_horizontal_order, parent, false);
    }

    @Override
    public OrderHorizontalAdapter.OrderHorizontalViewHolder onCompatCreateViewHolder(View realContentView, int viewType) {
        return new OrderHorizontalAdapter.OrderHorizontalViewHolder(realContentView);
    }

    @Override
    public void onBindViewHolder(OrderHorizontalAdapter.OrderHorizontalViewHolder holder, int position) {
        holder.setData(mContext, mList.get(position));

    }

    @Override
    public int getItemCount() {
        return mList == null ? 0 : mList.size();
    }


    static class OrderHorizontalViewHolder extends RecyclerView.ViewHolder {

        private  ImageView mGoodsIcon;

        public OrderHorizontalViewHolder(View itemView) {
            super(itemView);
            mGoodsIcon = (ImageView) itemView.findViewById(R.id.goods_icon);
        }

        public void setData(Context context, MyOrderResponse.OrderItemBean orderItemBean) {
            ImageUtils.loadGoodsPic(Utils.returnUrlShow(orderItemBean.getGoodsPic()),mGoodsIcon);
//            ViewGroup.LayoutParams layoutParams = mGoodsIcon.getLayoutParams();
//            layoutParams.width= 86;
//            layoutParams.height = 86;
//            mGoodsIcon.setLayoutParams(layoutParams);
        }
    }
}
